package com.mapper;

import com.domain.Box_data;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.service.Public_funtion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class Box_mysql {

    //快递柜当前柜子存放信息
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Resource
    private Public_funtion p;


    public List<Box_data> get_box(long data)
    {

        String sql="select * FROM Box WHERE"+
                " id  LIKE '%' AND "+
                " code  LIKE '"+data+"'";
        ;
        List list = jdbcTemplate.queryForList(sql);
        if(list.size()>0)
        {
            return list;
        }
        else
        {
            p.print_log("验证码错误，没有找到对应快递",2);
            return list;
        }
    }

    //    place:place,
//    status_id:status_id,
//    status_id:status_id,
//    phone:phone,
//    staff:staff,
//    otherIfo:otherIfo,
//    name:name,
//    time:time,
//    overtime:overtime,



    public boolean insert_box(Box_data box)
    {
        String send_string = "";
        String sql="INSERT INTO Box (id,locker_id,place,status_id,code,phone,boxtype,staff,otherIfo,name,time,yun_num,outtime,notice)" +
                " VALUES(" +
                "'',"+
                "'"+box.getLocker_id()+"',"+
                "'"+box.getPlace()+"',"+
                "'"+box.getStatus_id()+"',"+
                "'"+box.getCode()+"',"+
                "'"+box.getPhone()+"',"+
                "'"+box.getBoxtype()+"',"+
                "'"+box.getStaff()+"',"+
                "'"+box.getOtherIfo()+"',"+
                "'"+box.getName()+"',"+
                "'"+box.getTime()+"',"+
                "'"+box.getYun_num()+"',"+
                "'"+box.getOuttime()+"',"+
                "'"+box.getNotice()+"'"+
                ")";

        sql=sql.replaceAll("''","NULL");
        jdbcTemplate.update(sql);
        return true;
    }

    public String updata_box(Box_data box,String type)
    {
        String send_string = "";
        String sql="UPDATE Authority set locker_id='"+box.getId()
                +"', place_id='"+box.getLocker_id()
                +"', status_id='"+box.getLocker_id()
                +"', code_id='"+box.getLocker_id()
                +"', phone='"+box.getLocker_id()
                +"', staff_id='"+box.getLocker_id()
                +"', otherIfo='"+box.getLocker_id()
                +"', name='"+box.getLocker_id()
                +"', time='"+box.getLocker_id()
                +"', yun_num='"+box.getLocker_id()
                +"' WHERE  type like '"+type+"'";
        List list = jdbcTemplate.queryForList(sql);
        return "黑名单人员姓名已经添加";
    }

    public String remove_box(String num )
    {
        String send_string = "";
        String sql="DELETE FROM Box  WHERE   id= '"+num+"'";
        jdbcTemplate.update(sql);
        return "1";

    }

}
